<div class="doc-item" id="doc-1221"><h2 class="doc-item-name">re-partition<span class="namespace">(clojure.contrib.str-utils)</span></h2><ul class="var-arglists"><li>(<span class="var-name">re-partition</span> re string)</li></ul><div class="var-docstring"><p>Splits the string into a lazy sequence of substrings, alternating
  between substrings that match the patthern and the substrings
  between the matches.  The sequence always starts with the substring
  before the first match, or an empty string if the beginning of the
  string matches.</p><p>For example: (re-partition #&quot;[a-z]+&quot; &quot;abc123def&quot;)</p><p>Returns: (&quot;&quot; &quot;abc&quot; &quot;123&quot; &quot;def&quot;)</p></div><div class="var-source"><pre>; clojure/contrib/str_utils.clj:28
(defn re-partition
  [#^Pattern re string]
  (let [m (re-matcher re string)]
    ((fn step [prevend]
       (lazy-seq
        (if (.find m)
          (cons (.subSequence string prevend (.start m))
                (cons (re-groups m)
                      (step (+ (.start m) (count (.group m))))))
          (when (&lt; prevend (.length string))
            (list (.subSequence string prevend (.length string)))))))
     0)))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>